<div class="mb-15">
	<form class="form form-horizontal" id="form" method="post" action="{:url('AdminGroup/auth')}">
    <input type="hidden" name="id" value="{$group.id}"></input>
    <table class="table table-border table-bordered table-hover table-bg" id="auth_tree">
        <tbody>
            {$list}
        </tbody>
    </table>
    </form>
</div>
<script type="text/javascript" src="__LIB__/jquery/1.9.1/jquery.treetable.js"></script>
<script>
$(function() {
    $("#auth_tree").treeTable({indent:20});
    $('.auth_check_all').on('click', function(){
        $('.auth_check').prop("checked");
        $('.auth_check_all').prop("checked");
    });

    $('.auth_check').off('click').on('click', function(){

        var chk = $("input[type='checkbox']"),
            count = chk.length,
            num = chk.index($(this)),
            level_top = level_bottom =  chk.eq(num).attr('level');

        for(var i=num; i>=0; i--){
            var le = chk.eq(i).attr('level');
            if(eval(le) < eval(level_top)){
                chk.eq(i).prop("checked", true);
                var level_top = level_top-1;
            }
        }
        for(var j=num+1; j<count; j++){
            var le = chk.eq(j).attr('level');
            if(chk.eq(num).prop("checked")) {
                if(eval(le) > eval(level_bottom)) chk.eq(j).prop("checked", true);

                else if(eval(le) == eval(level_bottom)) break;
            }else{
                if(eval(le) > eval(level_bottom)) chk.eq(j).prop("checked", false);
                else if(eval(le) == eval(level_bottom)) break;
            }
        }
    });
});
</script>
